package com.tedu._05springmvc.controller;

import com.tedu._05springmvc.controller.mapper.UserMapper;
import com.tedu._05springmvc.controller.pojo.dto.UserDTO;
import com.tedu._05springmvc.controller.pojo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
public class UserController {
    //    @RequestMapping("/regUser")
//    @ResponseBody
//    public String reg(HttpServletRequest request){
//        System.out.println("开始进行用户注册!");
//        String username = request.getParameter("username");
//        String password = request.getParameter("password");
//        String nickname = request.getParameter("nickname");
//        String age = request.getParameter("age");
//        int i = Integer.parseInt(age);
//        System.out.println(username+","+password+","+nickname+","+age);
//        return "注册成功";
//    }
//@RequestMapping("/regUser")
//@ResponseBody
//public String reg(String username,String password,String nickname,int age){
//    System.out.println("开始进行用户注册!");
//    System.out.println(username+","+password+","+nickname+","+age);
//    return "注册成功";
//}
    @Autowired
    private UserMapper usermapper ;
    @RequestMapping("/regUser")
    @ResponseBody
    public String reg(UserDTO userDTO) {
        System.out.println("开始进行用户注册!");
        System.out.println(userDTO);
        User user = new User();
        user.setCreated(new Date());
        user.setNickname(userDTO.getNickname());
        user.setPassword((userDTO.getPassword()));
        user.setUsername(userDTO.getUsername());
        int insert = usermapper.insert(user);
        return insert>0?"注册成功":"注册失败";
    }
}
